#include "stdafx.h"

Button::Button(const std::string & ID) :ID(ID)
{

}

Button::~Button()
{
}

void Button::setMetrics(int left, int width, int top, int height)
{
	this->left = left;
	this->width = width;
	this->top = top;
	this->height = height;
}

void Button::setImages(Image * up, Image * hover, Image * down)
{
	this->up = up;
	this->hover = hover;
	this->down = down;
}

void Button::setImages(const std::string & up, const std::string & hover, const std::string & down)
{
	this->up = ImageMgr::getInstance()->get(up);
	this->hover = ImageMgr::getInstance()->get(hover);
	this->down = ImageMgr::getInstance()->get(down);
}

bool Button::hit(int x, int y)
{
	if (x >= left && x <= left + width && y >= top && y <= top + height)
	{
		return true;
	}
	else
	{
		return false;
	}
}

void Button::update(int state)
{
	this->state = state;
}

bool Button::render()
{
	switch (state)
	{
	case UP:
		if (up)
		{
			up->render(left, top);
		}
		else
		{
			std::cerr << "ERROR: up is null, Button ID: " << ID << std::endl;
		}
		break;
	case HOVER:
		if (hover)
		{
			hover->render(left, top);
		}
		else
		{
			std::cerr << "ERROR: hover is null, Button ID: " << ID << std::endl;
		}
		break;
	case DOWN:
		if (down)
		{
			down->render(left, top);
		}
		else
		{
			std::cerr << "ERROR: down is null, Button ID: " << ID << std::endl;
		}
		break;
	}

	return true;
}